define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wddj/invoice/index' + location.search,
                    invoice_file_url: 'wddj/invoice/invoice_file',
                    details_url: 'wddj/invoice/details',
                    table: 'wddj_invoice',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'look_up.invoice_title', title: __('Look_up'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'look_up.title_type', title: __('Look_up_type'), operate: false, searchList: {"1":__('个人'),"2":__('单位')}, formatter: Table.api.formatter.normal},
                        {field: 'look_up.invoice_type', title: __('Invoice_type'), operate: false, searchList: {"1":__('普通发票'),"2":__('专用发票')}, formatter: Table.api.formatter.normal},
                        {field: 'fees', title: __('Fees'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                                {
                                    name: 'invoice_file',
                                    text: __('上传发票'),
                                    title: __('上传发票'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    url: 'wddj/invoice/invoice_file',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible:function(row){
                                        if(row['status']==1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'details',
                                    text: __('查看详情'),
                                    title: __('查看详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    url: 'wddj/invoice/details',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },

                            ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        details: function () {
            Controller.api.bindevent();
        },
        invoice_file: function () {
            Controller.api.bindevent();
        },
        invoice_config: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
